<!DOCTYPE html>
<html lang="ch" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
  <style>
    body {
      background-color: #ffffff;
    }
  </style>
</head>
<body>
  <div class="layui-form layuimini-form" >
    <div class="layui-form-item">
      <label class="layui-form-label required">商品ID</label>
      <div class="layui-input-block">
        <input type="number" name="itemId" disabled="disabled" th:placeholder="${item.itemId}" th:value="${item.itemId}" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">商品售价</label>
      <div class="layui-input-block">
        <input type="text" name="listPrice" th:value="${item.listPrice}" lay-verify="required" lay-reqtext="售价不能为空" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">商品进价</label>
      <div class="layui-input-block">
        <input type="text" name="unitCost" th:value="${item.unitCost}" lay-verify="required" lay-reqtext="进价不能为空" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">商品存量</label>
      <div class="layui-input-block">
        <input type="text" name="quantity" th:value="${item.quantity}" lay-verify="required" lay-reqtext="存量不能为空" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">供货商</label>
      <div class="layui-input-block">
        <input type="text" name="supplierId" th:value="${item.supplierId}" lay-verify="required" lay-reqtext="存量不能为空" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">商品属性</label>
      <div class="layui-input-block">
        <input type="text" name="attr1" th:value="${item.attr1}" lay-verify="required" lay-reqtext="属性不能为空" class="layui-input">
      </div>
    </div>


    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
      </div>
    </div>
  </div>
  <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
  <script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  <script>
    layui.use(['form','miniTab'], function () {
      var form = layui.form,
              layer = layui.layer,
              miniTab = layui.miniTab;

      //监听提交
      form.on('submit(saveBtn)', function (data) {
        var url = window.location.href;
        var xhr = new XMLHttpRequest();
        var json = JSON.stringify(data.field)
        var index = layer.alert(json, {
          title: '最终的提交信息'
        }, function () {
          xhr.open("POST",url,true);
          xhr.setRequestHeader("Content-Type","application/json");
          xhr.send(json);
          xhr.onreadystatechange = function () {
            if(xhr.status == 4){
              if(xhr.readyState == 200||xhr.readyState == 304){
                window.alert('114');
              }
            }
          }
          layer.close(index);
          // layer.msg(data.msg,{icon:1,time:500},function(){
          //     setTimeout('window.location.load()',500);
          // });

          // layer.msg(data.msg, {icon:1,time:200}, function(){
          //   var index = parent.layer.getFrameIndex(window.name);
          //   alert(index);
          //   parent.location.reload(); //刷新父页面
          //   parent.layer.close(index);
          // });

          // window.history.back();

          // location.replace(document.referrer);

          setTimeout('window.location.assign(document.referrer)',500);

        });
        return false;
      });

    });

  </script>
</body>
</html>